package com.woniuxy.cq.phrase3.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.cq.phrase3.entity.Project;
import com.woniuxy.cq.phrase3.dao.ProjectMapper;
import com.woniuxy.cq.phrase3.entity.Sbp;
import com.woniuxy.cq.phrase3.entity.UserBm;
import com.woniuxy.cq.phrase3.entity.UserProject;
import com.woniuxy.cq.phrase3.service.IProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-09-07
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public void insertSxByUser(Integer bmId, Integer projectId, Integer userId) {
        projectMapper.insertSxByUser(bmId,projectId,userId);
    }

    @Override
    public Integer selectBmByuserName(String userName) {
        return projectMapper.selectBmByuserName(userName);
    }

    @Override
    public Integer selectIdByUserName(String userName) {
        return projectMapper.selectIdByUserName(userName);
    }

    @Override
    public List<UserBm> selectAllByUserBm() {
        return projectMapper.selectAllByUserBm();
    }

    @Override
    public IPage<UserProject> acceptedItems(int pageIndex, int pageSize, Integer checkStatusId) {
        Page<UserProject> page = new Page<UserProject>(pageIndex,pageSize);

        IPage<UserProject> Items =  projectMapper.acceptedItems(page,checkStatusId);
        return Items;
    }

    @Override
    public void updateProjectStatus(Integer projectId, String projectStatus) {
        projectMapper.updateProjectStatus(projectStatus,new Date(),projectId);
    }

    @Override
    public void outAcceptRange(Integer projectId) {
        projectMapper.outAcceptRange(projectId,new Date());
    }

    @Override
    public void incompleteData(Integer projectId) {
        projectMapper.incompleteData(projectId,new Date());
    }

    @Override
    public void successAccept(Integer projectId, Integer sxTotal) {
        projectMapper.successAccept(projectId,sxTotal,new Date());
    }

    @Override
    public IPage<Project> pageQuery2(int pageIndex, int pageSize, Integer userId, String projectPhase) {
        Page<Project> page = new Page<Project>(pageIndex,pageSize);

        IPage<Project> sxIPage =  projectMapper.pageQueryProject(page,userId,projectPhase);
        return sxIPage;

    }
}
